<template>
  <div class="shop-header">
    <div class="header-container">
      <!-- 左侧欢迎区域 -->
      <div class="welcome-section">
        <a href="/shop" class="welcome-link">
          <i class="el-icon-s-home welcome-icon"></i>
          <span class="welcome-text">欢迎来到悦购商城</span>
        </a>
      </div>
      
      <!-- 中间用户区域 -->
      <div class="user-section">
        <div class="user-info">
          <el-dropdown trigger="click" class="user-dropdown">
            <div class="user-avatar">
              <i class="el-icon-user-solid avatar-icon"></i>
              <span class="user-name">Hi, {{user.username}}</span>
              <i class="el-icon-arrow-down dropdown-icon"></i>
            </div>
            <template #dropdown>
              <el-dropdown-menu class="user-menu">
                <el-dropdown-item @click.native="$router.push('/mine')" class="menu-item">
                  <i class="el-icon-user"></i>
                  个人信息
                </el-dropdown-item>
                <el-dropdown-item @click.native="logOff" class="menu-item logout">
                  <i class="el-icon-switch-button"></i>
                  退出系统
                </el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
        
        <button class="register-btn" @click="$router.push('/register')">
          <i class="el-icon-plus"></i>
          注册
        </button>
      </div>
      
      <!-- 右侧导航区域 -->
      <div class="nav-section">
        <button class="nav-btn" @click="$router.push('/mine')">
          <i class="el-icon-s-custom"></i>
          <span>我的商城</span>
        </button>
        <button class="nav-btn" @click="$router.push('/cart')">
          <i class="el-icon-shopping-cart-2"></i>
          <span>购物车</span>
        </button>
        <button class="nav-btn" @click="$router.push('/myOrder')">
          <i class="el-icon-s-order"></i>
          <span>我的订单</span>
        </button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Header",
  data(){
    return{
      user: {}
    }
  },
  created() {
    let str = sessionStorage.getItem('user') || '{}';
    // 赋值
    this.user = JSON.parse(str);
  },
  methods: {

    logOff(){
      sessionStorage.clear();
      this.$message.success("您已登出");
      this.$router.push("/");
    }
  }
}
</script>

<style scoped>
/* 头部容器 */
.shop-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 1000;
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

/* 欢迎区域 */
.welcome-section {
  flex-shrink: 0;
}

.welcome-link {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: white;
  font-weight: 600;
  font-size: 18px;
  transition: all 0.3s ease;
}

.welcome-link:hover {
  color: #ffd700;
  transform: translateX(2px);
}

.welcome-icon {
  font-size: 20px;
}

/* 用户区域 */
.user-section {
  display: flex;
  align-items: center;
  gap: 20px;
}

.user-info {
  display: flex;
  align-items: center;
}

.user-dropdown {
  cursor: pointer;
}

.user-avatar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  color: white;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.user-avatar:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.avatar-icon {
  font-size: 16px;
}

.user-name {
  font-weight: 500;
  font-size: 14px;
}

.dropdown-icon {
  font-size: 12px;
  transition: transform 0.3s ease;
}

.user-dropdown:hover .dropdown-icon {
  transform: rotate(180deg);
}

.register-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
  border: none;
  border-radius: 20px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 10px rgba(255, 107, 53, 0.3);
}

.register-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(255, 107, 53, 0.4);
}

/* 导航区域 */
.nav-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 16px;
  color: white;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.nav-btn i {
  font-size: 14px;
}

/* 下拉菜单样式 */
.user-menu {
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  border: none;
  padding: 8px 0;
  min-width: 160px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  color: #2c3e50;
  font-size: 14px;
  transition: all 0.3s ease;
}

.menu-item:hover {
  background: #f8f9fa;
  color: #ff6b35;
}

.menu-item.logout:hover {
  background: #ffe6e6;
  color: #e74c3c;
}

.menu-item i {
  font-size: 14px;
  width: 16px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header-container {
    padding: 0 15px;
    height: 50px;
  }
  
  .welcome-text {
    display: none;
  }
  
  .user-name {
    display: none;
  }
  
  .nav-btn span {
    display: none;
  }
  
  .nav-btn {
    padding: 8px;
  }
  
  .register-btn {
    padding: 6px 12px;
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .header-container {
    padding: 0 10px;
  }
  
  .user-section {
    gap: 10px;
  }
  
  .nav-section {
    gap: 4px;
  }
  
  .nav-btn {
    padding: 6px 8px;
  }
}

/* 动画效果 */
.shop-header {
  animation: slideDown 0.5s ease-out;
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
</style>
